package com.xxx.mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxx.mall.dto.SkuDTO;
import com.xxx.mall.mapper.SkuStockMapper;
import com.xxx.mall.model.SkuStock;
import com.xxx.mall.service.SkuStockService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 库存信息 服务实现类
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-11-24
 */
@Service
public class SkuStockServiceImpl extends ServiceImpl<SkuStockMapper, SkuStock> implements SkuStockService {

    @Override
    public void updateBatch(List<SkuDTO> updateSkus) {
        List<SkuStock> skuStocks = updateSkus.stream().map(sku -> {
            SkuStock skuStock = new SkuStock();
            skuStock.setStock(sku.getStock());
            skuStock.setSkuId(sku.getSkuId());
            return skuStock;
        }).collect(Collectors.toList());
        baseMapper.updateStockBatch(skuStocks);
    }
}
